﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="Order_Maintain" CodeFile="Order_Maintain.aspx.cs" MasterPageFile="~/MasterPage.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <title>订单维护</title>
      <script src="../JavaScript/empchecks.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        //填单价
        function checkPrice(ddl, price, piecePrice, casePrice) {
            var txtPrice = document.getElementById(price);
            var ddl = document.getElementById(ddl);
            var lblPiecePrice = document.getElementById(piecePrice);
            var lblCasePrice = document.getElementById(casePrice);

            if (ddl[ddl.selectedIndex].value == 'CS') {
                txtPrice.value = lblCasePrice.innerText;
            }
            else if (ddl[ddl.selectedIndex].value == '') {
                txtPrice.value = '';
            }
            else {
                txtPrice.value = lblPiecePrice.innerText;
            }
        }


        ///算总金额
        function CalculateAmount(amount, price, rowAmount, ddlPieceDiscount, ddlRowDiscount) {
            var txtPrice = document.getElementById(price);
            var txtAmount = document.getElementById(amount);
            var txtRowAmount = document.getElementById(rowAmount);
            var ddlPieceDiscount = document.getElementById(ddlPieceDiscount);
            var ddlRowDiscount = document.getElementById(ddlRowDiscount);

            //        var input = event.srcElement;
            var amount = txtAmount.value; //input.value;
            var price = txtPrice.value;

            var pieaceDiscount = ddlPieceDiscount[ddlPieceDiscount.selectedIndex].text;
            var rowDiscount = ddlRowDiscount[ddlRowDiscount.selectedIndex].text;

            //        alert(pieaceDiscount);
            //        alert(rowDiscount);
            //        
            if (pieaceDiscount != '' && rowDiscount != '') {
                txtRowAmount.value = (amount * price * pieaceDiscount * rowDiscount).toFixed(2);
            }
            else if (pieaceDiscount == '' && rowDiscount != '') {
                txtRowAmount.value = (amount * price * rowDiscount).toFixed(2);
            }
            else if (pieaceDiscount != '' && rowDiscount == '') {
                txtRowAmount.value = (amount * price * pieaceDiscount).toFixed(2);
            }
            else if (pieaceDiscount == '' && rowDiscount == '') {
                txtRowAmount.value = (amount * price).toFixed(2);
            }
        }
    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script type="text/javascript">
    function formatDate(v) {
        if (v instanceof Date) {
            var y = v.getFullYear();
            var m = v.getMonth() + 1;
            var d = v.getDate();
            var h = v.getHours();
            var i = v.getMinutes();
            var s = v.getSeconds();
            var ms = v.getMilliseconds();
            if (ms > 0)
                return y + '/' + m + '/' + d + ' ' + h + ':' + i + ':' + s
						+ '.' + ms;
            if (h > 0 || i > 0 || s > 0)
                return y + '/' + m + '/' + d + ' ' + h + ':' + i + ':' + s;
            return y + '-' + m + '-' + d;
        }
        return '';
    }
    $(function () {
        $('#<%=txtDeliveryDate.ClientID %>').datebox({
            currentText: '今天',
            closeText: '关闭',
            disabled: false,
            required: false,
            missingMessage: '必填',
            formatter: formatDate
        });
    });
    $(function () {
        $('#<%=txtArrivalDate.ClientID %>').datebox({
            currentText: '今天',
            closeText: '关闭',
            disabled: false,
            required: true,
            missingMessage: '必填',
            formatter: formatDate
        });
    });

    function checktxtArrivalDate() {
        var ArrivalDate = $('#<%=txtArrivalDate.ClientID %>').datebox('getValue');
        if (ArrivalDate == "") {
            alert("请选择收货日期");
            return false;
        }
        else {

            return HaveCheck('chkConfirm', '没有选择任何项');
             
        }

    }

    function updatePrice(txtamount, txtprice, lbltotal) {
       
        $get(lbltotal).innerText = ($get(txtamount).value * $get(txtprice).value).toFixed(4) ;
        
    }
</script>
    <div>
        <asp:Panel ID="pnlOrder" runat="server">
            <table id="wsd_inputtable">
                <tr>
                    <td colspan="6" class="tabletitle">
                        <font color="red" size="2"><b>提示:*为必填项</b></font> 客户:<asp:Label runat="server" ID="lblCustomer"></asp:Label>
                    </td>
                </tr>
               
                <tr>
                    <td class="tablefield">
                        订单日期:
                    </td>
                    <td nowrap="nowrap">
                        <asp:TextBox ID="txtStartDate" runat="server" ReadOnly="True" Enabled="False"></asp:TextBox>
                    </td>
                    <td class="tablefield">
                        计划发货日期
                    </td>
                    <td nowrap="nowrap">
                        <asp:TextBox ID="txtDeliveryDate" runat="server" class="default"></asp:TextBox>
                    </td>
                    <td class="tablefield">
                        &nbsp;确认人:</td>
                    <td nowrap="nowrap">
                        <asp:TextBox ID="txtConfirmUser" runat="server" Enabled="False" ReadOnly="True"></asp:TextBox>
                    </td>
                   
                </tr>
                <tr>
                    <td class="tablefield">
                        经销商:</td>
                    <td nowrap="nowrap">
                        <asp:TextBox ID="txtChains" runat="server" Enabled="False" ReadOnly="True"></asp:TextBox>
                    </td>
                    <td class="tablefield">
                        <font color="red" size="2"><b>*</b></font>实际收货日期:
                    </td>
                    <td nowrap="nowrap">
                        <asp:TextBox runat="server" ID="txtArrivalDate" type="text" class="default"
                            ></asp:TextBox>
                        <br />
                    </td>
                    <td class="tablefield">
                        &nbsp;确认时间:
                    </td>
                    <td nowrap="nowrap">
                        <asp:TextBox ID="txtConfirmDate" runat="server" Enabled="False" ReadOnly="True"></asp:TextBox>
                    </td>
                </tr>
                 <tr>
                    <td class="tablefield">
                        订单原始金额(元):</td>
                    <td nowrap="nowrap">
                        <asp:Label Font-Bold="true" ForeColor="red" ID="txtOriginal" runat="server" />
                    </td>
                    <td class="tablefield">
                        订单折扣金额(元):
                    </td>
                    <td nowrap="nowrap">
                       <asp:Label ID="txtDiscount" Font-Bold="true" ForeColor="red"  runat="server" />
                       
                    </td>
                    <td class="tablefield">
                       订单实际支付金额(元):
                    </td>
                    <td nowrap="nowrap">
                       <asp:Label ID="txtFact" runat="server" Font-Bold="true" ForeColor="red"  />
                    </td>
                </tr>
                <tr>
                  
                    <td class="tablefield">
                        有效:
                    </td>
                    <td colspan=5>
                        
                        <asp:CheckBox ID="chkCancelled" runat="server" Checked="true" Enabled="false" />
                    </td>
                   
                </tr>
        
            </table>
            <br />
            <table id="wsd_inputtable">
                <tr>
                    <td width="100%" class="tabletitle">
                        产品列表
                    </td>
                </tr>
            </table>
             <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
        <ContentTemplate>
            <table id="wsd_listtable">
                <tr>
                    <td>
                        <asp:GridView Width="100%" ID="gvOrderLineList" GridLines="None" runat="server" AutoGenerateColumns="False"
                            EmptyDataText="没有可显示的数据." EmptyDataRowStyle-Font-Bold="true" EmptyDataRowStyle-HorizontalAlign="Center"
                            DataKeyNames="ID,ARRIVAL_date" HtmlEncode="false" EnableEmptyContentRender="true"
                            OnRowDataBound="gvOrderLineList_RowDataBound" OnRowDeleting="gvOrderLineList_RowDeleting">
                            <HeaderStyle CssClass="titlist" />
                            <EmptyDataRowStyle Font-Bold="True" HorizontalAlign="Center" />
                            <Columns>
                                <asp:TemplateField HeaderText="ID" Visible="false">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblID" Text='<%# Eval("ID")%>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="OrderID" Visible="false">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblLineID" Text='<%# Eval("LineID")%>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                 <asp:TemplateField ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center">
                                <ItemTemplate>
                                    <image  src='<%# "../SMALLIMAGE.aspx?H=80&W=80&ID=" + Eval("PHOTO_ID").ToString()  %>' ></image>
                                     </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                <ItemStyle HorizontalAlign="Center"></ItemStyle>
                            </asp:TemplateField>
                                <asp:BoundField HeaderText="产品代码" DataField="CODE" />
                                <asp:BoundField DataField="FORMNAME" HeaderText="系列" />
                               <%-- <asp:BoundField HeaderText="本品名称" DataField="DESCRIPTION2" />--%>
                                <asp:BoundField HeaderText="产品名称" DataField="DESCRIPTION" />
                                <asp:BoundField DataField="SHORT_DESCRIPTION" HeaderText="产品简称" Visible="false" />
                               
                                <asp:TemplateField HeaderText="数量">
                                    <ItemTemplate>
                                        <asp:TextBox runat="server" style="width:40px" ID="txtAmount" MaxLength="4" Text='<%# string.Format("{0:G}",(Convert.ToDecimal(Eval("QUANTITY_ORDERED"))))%>'
                                            size="5" ></asp:TextBox>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="发货数量">
                                    <ItemTemplate>
                                        <asp:TextBox runat="server" ID="txtQTYShip" MaxLength="8" Text='<%# Eval("QTYShip").ToString()==string.Empty?"": string.Format("{0:G}",Convert.ToDecimal(Eval("QTYShip")))%>'
                                            size="8" style="width:50px" ></asp:TextBox>
                                        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtQTYShip"
                                            ValidationExpression="^\d{1,8}$" Display="Dynamic" ErrorMessage="发货数量应为最大8位正整数" Text="发货数量应为最大8位正整数" runat="server"></asp:RegularExpressionValidator>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" Text="发货数量不能为空" runat="server"
                                            ErrorMessage="发货数量不能为空" Display="Dynamic"  ControlToValidate="txtQTYShip"></asp:RequiredFieldValidator>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="收货数量">
                                    <ItemTemplate>
                                        <asp:TextBox style="width:50px" Enabled="false" runat="server" ID="txtQTYReceive" MaxLength="8" Text='<%# Eval("QTYReceive").ToString()==string.Empty?"": string.Format("{0:G}",Convert.ToDecimal(Eval("QTYReceive")))%>'
                                            size="5" ></asp:TextBox>
                                        <asp:RegularExpressionValidator ID="RegularExpressionValidator2"  ControlToValidate="txtQTYReceive" Display="Dynamic"
                                            ValidationExpression="^\d{1,8}$" ErrorMessage="收货数最多6位正整数" Text="收货数最多6位正整数" runat="server"></asp:RegularExpressionValidator>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator6"   Text="收货数不能为空" runat="server"  Display="Dynamic"
                                            ErrorMessage="收货数不能为空" ControlToValidate="txtQTYReceive"></asp:RequiredFieldValidator>
                                        <asp:RangeValidator ID="RangeValidator1"  runat="server" ControlToValidate="txtQTYReceive"
                                            Type="Integer" ErrorMessage="收货数必须介于1~999999" Display="Dynamic" MinimumValue="1" MaximumValue="999999"></asp:RangeValidator>
                                        <asp:CompareValidator ID="CompareValidator2"   runat="server" ControlToValidate="txtQTYReceive"  Display="Dynamic"
                                            Type="Integer" ControlToCompare="txtQTYShip" ErrorMessage="收货数不能大于发货数" Operator="LessThanEqual"></asp:CompareValidator>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="价格">
                                    <ItemTemplate>
                                        <asp:TextBox  style="width:50px" runat="server"  ReadOnly="false" ID="txtLinePrice" MaxLength="13" Text='<%# string.Format("{0:F}",(Convert.ToDecimal(Eval("PRICE"))))%>'
                                            size="16"></asp:TextBox>
                                       
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator9" Display="Dynamic" Text="收货单价不能为空" runat="server"
                                            ErrorMessage="收货单价不能为空" ControlToValidate="txtLinePrice"></asp:RequiredFieldValidator>
                                    </ItemTemplate>
                                </asp:TemplateField>      
                                 <asp:TemplateField HeaderText="金额">
                                    <ItemTemplate>
                                        <asp:Label ID="lbl_price" runat="server" Text='<%# string.Format("{0:F}",(Convert.ToDecimal(Eval("LINE_AMOUNT")))) %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>                          
                              
                                <asp:TemplateField HeaderText="收货日期">
                                    <ItemTemplate>
                                        <asp:Label ID="lblARRIVAL_date" runat="server" Text='<%# Jumpton.SFA.Server.BusinessRule.BusinessLogic.GetDateTime(Eval("ARRIVAL_date").ToString(),"yyyyMMddHHmmss","yyyy-MM-dd")  %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="订单状态">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblStatusDescription" Text='<%# Jumpton.SFA.Server.Entity.ORDER_LINES.GetOrderLineStatus(Convert.ToInt32(Eval("OrderLineStatus"))) %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            
                                <asp:TemplateField ControlStyle-Width="40px">
                                    <HeaderTemplate>
                                         <input  type="checkbox" id="chkAll" name="chkAll" onclick="Check1(this,'chkConfirm')" />全选
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="chkConfirm" runat="server" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                               
                                
                            </Columns>
                            <RowStyle CssClass="evenline" />
                            <AlternatingRowStyle CssClass="oddline" />
                        </asp:GridView>
                    </td>
                
                </tr>
            </table>
              </ContentTemplate>

        </asp:UpdatePanel>
            <br />
            <table id="wsd_inputtable">
                <tr>
                    <td width="100%" class="tabletitle" colspan="2">
                        操作选项
                    </td>
                </tr>
                <tr>
                    <td class="buttonarea">
                        &nbsp;</td>
                    <td class="buttonarea">
                        <asp:Button ID="btnSave0" runat="server" class="wsd_button2" Text="保 存 " 
                            OnClick="btnSave0_Click" OnClientClick="return checktxtArrivalDate();"  />
                        <asp:Button ID="btnSave" runat="server" class="wsd_button2" 
                            OnClick="btnSave_Click" OnClientClick="return checktxtArrivalDate();" 
                            Text="确  认" style="height: 21px" />
                        &nbsp;&nbsp;
                        <asp:Button ID="btnCancel" runat="server" class="wsd_button2" Text="返  回" CausesValidation="false"
                            OnClick="btnCancel_Click" />
                        &nbsp;&nbsp;
                    </td>
                </tr>
            </table>
            <br />
        </asp:Panel>
    </div>
</asp:Content>
